<?php
// Add admin pages
function fadi_options_page() {
    add_theme_page( 'Theme Options', 'Theme Options', 'edit_theme_options', basename(__FILE__), 'fadi_options' );
    
}
add_action('admin_menu', 'fadi_options_page');


function fadi_options()
{
	if(isset($_POST['save_social'])) { fadi_save_options_social(); }
	
	if(isset($_POST['save_home_options'])) { fadi_save_options_home(); }
	?>
    <div class="wrap">
        <div id="icon-options-general" class="icon32"><br /></div>
		<h2><?php _e('FadiGaziri Theme Options', 'fadi'); ?></h2>
        <br />
        <form method="post" action="">
        <fieldset>
            <legend><h3>Social Links</h3></legend>
            <p>
            <label>Facebook:</label> <input type="text" name="nm_fadi_fb_link" class="regular-text" value="<?php _e(get_option('nm_fadi_fb_link'))?>" />
            </p>
            <p>
            <label>Twitter: </label><input type="text" name="nm_fadi_twitter_link" class="regular-text" value="<?php _e(get_option('nm_fadi_twitter_link'))?>" />
            </p>
            <p>
            <label>Linkedin: </label><input type="text" name="nm_fadi_linkedin_link" class="regular-text" value="<?php _e(get_option('nm_fadi_linkedin_link'))?>" />
            </p>
            <input type="submit" class="button" value="<?php _e('Save Changes', 'fadi'); ?>" name="save_social" />      
        </fieldset>
        </form>
        
        <br /><br />
        
        <form method="post" action="">
        <fieldset>
            <legend><h3>Homepage Category [<?php _e(get_option('nm_fadi_homepage_cat'))?>]</h3></legend>
            <p>
            <label>Select Category: <em>Show at top block</em></label>
            <select name="nm_fadi_homepage_cat"> 
             <option value=""><?php echo esc_attr(__('Select Category')); ?></option> 
             <?php 
              $categories=  get_categories(); 
              foreach ($categories as $category) {
                $option = '<option value="'.$category->cat_ID.'">';
                $option .= $category->cat_name;
                $option .= '</option>';
                echo $option;
              }
             ?>
            </select>
            </p>
            <input type="submit" class="button" value="<?php _e('Save Changes', 'fadi'); ?>" name="save_home_options" /> 
        </fieldset>
        </form>
        
   </div>
<?php

}



// Saving social options
function fadi_save_options_social()
{
	update_option('nm_fadi_fb_link', $_POST['nm_fadi_fb_link']);
	update_option('nm_fadi_twitter_link', $_POST['nm_fadi_twitter_link']);
	update_option('nm_fadi_linkedin_link', $_POST['nm_fadi_linkedin_link']);
	
	?>   
    <div class="updated">Options Saved</div>
    <?php
}


// Saving homepage options
function fadi_save_options_home()
{
	update_option('nm_fadi_homepage_cat', $_POST['nm_fadi_homepage_cat']);
	
	?>   
    <div class="updated">Options Saved</div>
    <?php
}
?>

